package com.ItemsRent.model;

import java.util.HashMap;
// default package
import java.util.Iterator;


/**
 * ItemType entity. @author MyEclipse Persistence Tools
 */

public class ItemType  implements java.io.Serializable {


    // Fields    

     private Integer typeId;
     private String typeName;
     private String typeDescription;
     private String ptype;
     //private Set items = new HashSet(0);
     private HashMap<String,Integer> map = new HashMap<String,Integer>();
     
     //初始化
     {
    	 map.clear();
    	 map.put("电子产品", 1);
    	 map.put("书籍/音像", 2);
    	 map.put("运动器材", 3);
    	 map.put("生活用品", 4);
    	 map.put("会议用品", 5);
    	 map.put("其他", 6);
    	 map.put("手机", 7);
    	 map.put("平板电脑", 8);
    	 map.put("台式电脑", 9);
    	 map.put("配件", 10);
    	 map.put("教材", 11);
    	 map.put("参考书", 12);
    	 map.put("杂志", 13);
    	 map.put("电其他书籍", 14);
    	 map.put("球类", 15);
    	 map.put("健身器材", 16);
    	 map.put("自行车", 17);
    	 map.put("水上运动器材", 18);
    	 map.put("其他器材", 19);
    	 map.put("衣服", 20);
    	 map.put("鞋子", 21);
    	 map.put("箱包", 22);
    	 map.put("日用品", 23);
    	 map.put("清洁工具", 24);
    	 map.put("其他用品", 25);
    	 map.put("办公耗材", 26);
    	 map.put("音响设备", 27);
    	 map.put("影像设备", 28);
    	 map.put("笔记本电脑", 29);
     }

    // Constructors

    /** default constructor */
    public ItemType() {
    }

	/** minimal constructor */
    public ItemType(String typeName) {
        this.typeName = typeName;
        this.typeId=map.get(this.typeName);
        this.beFull();
    }
    
    /**
     * 根据种类ID构造对象
     **/
    public ItemType(int typeId){
    	this.typeId=typeId;
    	Iterator<String> iter = map.keySet().iterator();
    	String key;
    	while(iter.hasNext()){
    		key = iter.next();
    		if(map.get(key)==typeId){
    			this.typeName=key;
    			break;
    		}
    	}
    	this.beFull();
    }
    
    public ItemType(String typeName, String ptype) {
    	this.typeId = map.get(typeName);
        this.typeName = typeName;
        this.ptype = ptype;
    }
    
    public ItemType(Integer typeId,String typeName, String ptype) {
    	this.typeId=typeId;
        this.typeName = typeName;
        this.ptype = ptype;
    }
    
    /** full constructor */
    public ItemType(String typeName, String typeDescription, String ptype) {
        this.typeName = typeName;
        this.typeDescription = typeDescription;
        this.ptype = ptype;
    }

   
    // Property accessors

    public Integer getTypeId() {
        return this.typeId;
    }
    
    public void setTypeId(Integer typeId) {
        this.typeId = typeId;
    }

    public String getTypeName() {
        return this.typeName;
    }
    
    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getTypeDescription() {
        return this.typeDescription;
    }
    
    public void setTypeDescription(String typeDescription) {
        this.typeDescription = typeDescription;
    }

    public String getPtype() {
        return this.ptype;
    }
    
    public void setPtype(String ptype) {
        this.ptype = ptype;
    }
    
    @Override
    public String toString(){
    	return "物品ID: "+ this.typeId + " " + this.typeName + " " + this.typeDescription + " " + this.ptype;
    }
    
    private void beFull(){
    	if(1<=this.typeId && this.typeId<=6) this.ptype=null;
    	else if(this.typeId<=10) this.ptype="电子产品";
    	else if(this.typeId<=14) this.ptype="书籍/音像";
    	else if(this.typeId<=19) this.ptype="运动器材";
    	else if(this.typeId<=24) this.ptype="生活用品";
    	else if(26<=this.typeId && this.typeId<=28) this.ptype="会议用品";
    	else if(this.typeId==29) this.ptype="电子产品";
    	else this.ptype="其他";
    }
    
}